﻿using Harmontronics.DataAccess.IOperate.Business;
using Harmontronics.Model.Common;
using Harmontronics.Model.Dto.Model;
using Harmontronics.Model.Entitys;
using Harmontronics.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Harmontronics.DataAccess.Operate.Business
{
    public class MaterialOperate : IMaterialOperate
    {
        private HcDbContext _db { get; set; }
        public MaterialOperate(HcDbContext db)
        {
            _db = db;
        }
        //查询所有
        public List<Material> GetAllMaterialList()
        {

            return _db.Materials.ToList();
        }

        public Material GetMaterialById(string id)
        {
            return _db.Materials.SingleOrDefault(i => i.MaterialId == id);
        }

        public List<Material> GetMaterialByIdList(List<string> ids)
        {
            return _db.Materials.Where(i => ids.Contains(i.MaterialId)).ToList();
        }

        public void AddMaterial(Material entity)
        {
            entity.CreateTime = DateTime.Now;
            entity.UpdateTime = DateTime.Now;
            _db.Materials.Add(entity);
        }

        public void UpdateMaterial(Material entity)
        {
            entity.UpdateTime = DateTime.Now;
            _db.Materials.Update(entity);
        }

        public void DeleteMaterial(Material entity)
        {
            _db.Materials.Remove(entity);
        }

        public void BatchDelMaterial(List<Material> entity)
        {
            _db.Materials.RemoveRange(entity);

        }
    }
}
